package com.tianbing.adlottery.json;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.log4j.Logger;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

/**
 * MultiActionController for the image list/upload UI.
 * 
 * @author Conan Chen
 * @since 2006.12.15
 */
public class AjaxJsonController extends MultiActionController {
	Logger logger = Logger.getLogger(AjaxJsonController.class.getName());

	private String jsonView;

	public ModelAndView getRelatedSites(HttpServletRequest request, HttpServletResponse response) throws Exception {

		ModelAndView mv = new ModelAndView(jsonView);
		Map model = mv.getModel();

		String uriPrePath = ServletRequestUtils.getStringParameter(request, "uriPrePath", null);
		if (uriPrePath != null) {
			List result = new ArrayList();

			for (int i = 0; i < 3; i++) {
				ArrayList s = new ArrayList();
				//uriPrePath,name,icon,foxySearchFlag,groupNo,groupItemNo,createdDate,lastUpdatedDate
				s.add("http://www.eetchina" + i + ".com");
				s.add("sn中文" + i);
				s.add("icon.jpg");
				s.add("N");
				s.add("" + i);
				s.add("" + i);
				s.add(System.currentTimeMillis() / 1000);
				s.add(System.currentTimeMillis() / 1000);

				result.add(s);
			}
			JSONArray jsonArray = JSONArray.fromObject(result);

			model.put("ajax_json", jsonArray);

			logger.info("uriPrePath="+uriPrePath+" related sites=" + jsonArray.toString());
		}
		
		return mv;
	}

	/**
	 * @return the jsonView
	 */
	public String getJsonView() {
		return jsonView;
	}

	/**
	 * @param jsonView the jsonView to set
	 */
	public void setJsonView(String jsonView) {
		this.jsonView = jsonView;
	}

}
